/**
 *
 */
package de.cbf.cam.dsa.rcp.model.entities;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;

import de.cbf.util.uuidheader.entities.NamedEntity;
import de.cbf.util.uuidheader.entities.UUIDHeader;
import de.cbf.util.uuidheader.exceptions.EntityMergeException;

/**
 * @author salter
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
public class RCPPerked extends NamedEntity {
	@XmlElementWrapper(name="perks")
	@XmlElement(name="perk")
	protected List<PerkDSA> 		weightedPerks		;

	protected String displayName;
	/**
	 *
	 */
	public RCPPerked() {
		super();
	}

	protected void init() {
		super.init();
		weightedPerks		= new ArrayList<PerkDSA>();
	}

	/* (non-Javadoc)
	 * @see de.cbf.util.uuidheader.entities.UUIDHeader#doMergeDataFrom(de.cbf.util.uuidheader.entities.UUIDHeader, boolean)
	 */
	@Override
	protected void doMergeDataFrom(UUIDHeader entity, boolean i_am_older)
			throws EntityMergeException {
		super.doMergeDataFrom(entity, i_am_older);
		if (entity instanceof RCPPerked) {
			RCPPerked correctEntity = (RCPPerked) entity;
			if(i_am_older){
				this.weightedPerks.clear();
				this.weightedPerks.addAll(correctEntity.weightedPerks);
				this.displayName = correctEntity.displayName;
			}
		}else{
			String mergeEntityClass = entity == null? "null":entity.getClass().getName();
			String errorMsg ="EntityToMerge "+mergeEntityClass+" does not fit class:"+this.getClass().getName();
			throw new EntityMergeException(errorMsg);
		}
	}

	@Override
	public Object clone() throws CloneNotSupportedException {
		RCPPerked clone = new RCPPerked();
		try {
			clone.mergeDataFrom(this);
		} catch (EntityMergeException e) {
			throw new CloneNotSupportedException(e.getLocalizedMessage());
		}
		return clone;
	}

	public List<PerkDSA> getWeightedPerks() {
		return weightedPerks;
	}

	public void setWeightedPerks(List<PerkDSA> weightedPerks) {
		this.weightedPerks = weightedPerks;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}




}
